<template>
  <div class="table_continer">
    <div>
      <!-- 列表 ------------------------------------------------------------------------------------------------------->
      <el-table ref="multipleTable" :data="tableData" tooltip-effect="dark" style="width: 100%"
        @selection-change="handleSelectionChange">
        <el-table-column label="序号" width="100">
          <template slot-scope="scope">
            <div>{{ scope.$index + 1 }}</div>
          </template>
        </el-table-column>
        <el-table-column label="入库单号" min-width="120">
          <template slot-scope="scope">
            <el-link @click="handledetailed(scope.row.warehousingId)" type="primary">
              {{ scope.row.warehousing.warehousingNum || '-' }}
            </el-link>
          </template>
        </el-table-column>
        <el-table-column label="入库类型">
          <template slot-scope="scope">
            {{ scope.row.warehousing.purchaseId }}
            <div>{{ ['采购入库', '盘盈入库', '还回入库', '其他入库'][scope.row.warehousing.type] }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="consPriceAndAmountVo.materialNum" label="物料编号" show-overflow-tooltip />
        <el-table-column prop="consPriceAndAmountVo.materialName" label="物料名称" show-overflow-tooltip />
        <el-table-column prop="consPriceAndAmountVo.typeName" label="类别">
          <template slot-scope="{row}">
            <div>{{ row.consPriceAndAmountVo && row.consPriceAndAmountVo.typeName || '-' }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="consPriceAndAmountVo.model" label="规格型号" show-overflow-tooltip>
          <template slot-scope="{row}">
            <div>{{ row.consPriceAndAmountVo && row.consPriceAndAmountVo.model || '-' }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="consPriceAndAmountVo.unitName" label="单位" />
        <el-table-column prop="batch" label="批次" show-overflow-tooltip />
        <el-table-column prop="warehousing.storehouseName" label="入库仓库" show-overflow-tooltip />
        <el-table-column prop="amount" label="入库数量" />
        <el-table-column prop="warehousing.confirmTime" label="确认入库时间" min-width="160" />
        <el-table-column label="创建部门" align="center" min-width="180" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ scope.row.deptName || '-' }}
          </template>
        </el-table-column>
        <el-table-column label="创建人" align="center" min-width="180" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ scope.row.createBy || '-' }}
          </template>
        </el-table-column>
      </el-table>
      <!-- ------------------------------------------------------------------------------------------------------------>
    </div>
    <!-- --------------------------------分页器---------------------------------------------------------- -->
    <div class="table_continer_pagination">
      <el-pagination background :current-page="pageParams.pageNum" :page-sizes="[10, 20, 50, 100]"
        :page-size="pageParams.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="pagination.total"
        @size-change="handleSizeChange" @current-change="handleCurrentChange" />
    </div>
  </div>
</template>

<script>
/** 拉取列表远程方法 ---------------------------------------------------------------------------------------------------------- */
import { listAndMe } from '@/api/deviceConsumable/stock'
/** ------------------------------------------------------------------------------------------------------------------------- */
import { pageCount } from '@/utils/pagination'
/** 查询参数处理 ---------------------------------------------------------------------------------------------------------- */
function processQueryParams (queryParams, pageParams) {
  const params = Object.assign({}, queryParams, pageParams)
  return params
}
/** ------------------------------------------------------------------------------------------------------------------------- */

export default {
  name: 'PaginationTable',
  data () {
    return {
      pagination: {
        total: 1,
        pageCount: 1
      },
      pageParams: {
        pageNum: 1,
        pageSize: 10,
        /** 列表默认排序字段 ---------------------------------------------------------------------------------------------------------- */
        orderByColumn: 'confirm_time',
        /** ------------------------------------------------------------------------------------------------------------------------- */
        isAsc: 'desc'
      },
      queryParams: null,
      tableData: [],
      multipleSelection: []
    }
  },
  mounted () {
    this.refreshList()
  },
  methods: {
    refreshList () {
      let params = processQueryParams(this.queryParams, this.pageParams)
      console.log('查询参数', params);
      // --------consolelog('查询参数', params)
      listAndMe({
        ...params,
        'warehousing.status': '1'
      }).then((res) => {
        console.log('获取列表', res);
        // --------consolelog('获取列表', res)
        this.pagination.total = res.total
        this.pagination.pageCount = pageCount(this.pagination.total, this.pageParams.pageSize)
        this.tableData = res.data
      })
    },
    handleQuery (queryParams) {
      this.queryParams = queryParams
      this.refreshList()
    },
    handleSizeChange (value) {
      this.pageParams.pageSize = value
      this.refreshList()
    },
    handleCurrentChange (value) {
      this.pageParams.pageNum = value
      this.refreshList()
    },
    handleSelectionChange (value) {
      // console.log('handleSelectionChange', value)
    },
    // 点击编号跳转采购单详情-----------------------------
    handledetailed (id) {
      this.$emit('click_create_reception', id)
    },
    /** 传递点击【审核流程】事件 ---------------------------------------------------------------------------------------------------------- */
    handleEdit (val) {
      this.$emit('click_edit', val)
    },
    /** 传递点击【审核】事件 ---------------------------------------------------------------------------------------------------------- */
    handleAudit (purchaseId, auditId) {
      this.$emit('click_audit', { purchaseId, auditId })
    }
  }
}
</script>
<style lang="scss" scoped>
.table_continer {
  border-radius: 5px;

  &_pagination {
    background-color: white;
    padding: 10px;
    margin-bottom: 10px;
  }
}
</style>
